import http from "@/http";

export const userListApi = (params: IUserListParams): RES<IUserListModel> =>
  http.get("/admin/list", { params });

export const switchUserStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserApi = (params: IUserModel): RES<IUserModel> =>
  http.post("/admin/register", params);

export const getUserByIdApi = (id: number): RES<IUserModel> =>
  http.get(`/admin/${id}`);

export const updateUserapi = (params: IUserModel): RES<any> =>
  http.post(`/admin/update/${params.id}`, params);

export const getRoleListApi = (): RES<IRoleModel[]> =>
  http.get("/role/listAll");

export const getRoleByAdminIdApi = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

export const updateUserRoles = (
  adminId: number,
  roleIds: number[]
): RES<number> =>
  http.post(`/admin/role/update?adminId=${adminId}&roleIds=${roleIds}`);

// 角色列表
export const roleListApi = (
  params: IUserListParams
): RES<IRoleList<RoleList>> => http.get("role/list", { params });

// 修改用户角色状态
export const updateRoleStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/role/updateStatus/${id}?status=${status}`);

// 添加加用户
export const addRoleApi = (params: RoleList): RES<RoleList> =>
  http.post("/role/create", params);

// 编辑角色
export const updateRolesApi = (params: RoleList): RES<number> =>
  http.post(`/role/update/${params.id}`, { params });

// 获取角色相关资源
export const getRourceListByRoleIdApi = (
  roleId: number
): RES<IResourceModel[]> => http.get(`/role/listResource/${roleId}`);

//  获取所有角色
export const resourceListAllApi = (): RES<IResourceModel[]> =>
  http.get("/resource/listAll");

//查询所有后台资源分类
export const resourceCategoryAllApi = (): RES<IResourceCategoryModel[]> =>
  http.get("/resourceCategory/listAll");

// g给角色分配资源
export const allocResourceApi = (params: IallocResourceParams): RES<any> =>
  http.post(
    `/role/allocResource?roleId=${
      params.roleId
    }&resourceIds=${params.resourceIds.join(",")}`
  );

// 获取菜单
export const treeListApi = (): RES<ItreeMenu[]> => http.get("/menu/treeList");
